<template>
	<view class="wrap">
		<u-form :model="model" :rules="rules" ref="uForm">
			<u-form-item label-width="350"
				:label-position="labelPosition" label="倒扣的深度(m)" prop="depth">
				<u-input :border="border" placeholder="请输入倒扣的深度" v-model="model.depth" type="digit"></u-input>
			</u-form-item>
			<u-form-item label-width="350"
				:label-position="labelPosition" label="井内管柱每米的重量(t)" prop="pipeWeight">
				<u-input :border="border" placeholder="请输入井内管柱每米的重量" v-model="model.pipeWeight" type="digit"></u-input>
			</u-form-item>
			<u-form-item label-width="350"
				:label-position="labelPosition" label="井内管柱截面积(㎡)" prop="pipeArea">
				<u-input :border="border" placeholder="请输入井内管柱截面积" v-model="model.pipeArea" type="digit"></u-input>
			</u-form-item>
			<u-form-item label-width="350"
				:label-position="labelPosition" label="井内液体的密度(t/m³)" prop="liquidDensity">
				<u-input :border="border" placeholder="请输入井内液体的密度" v-model="model.liquidDensity" type="digit"></u-input>
			</u-form-item>
		</u-form>

		<u-button type="primary" @click="submit">计算</u-button>

		<view class="u-config-wrap">
			<view class="u-config-item">
				<view class="u-item-title">计算结果</view>
				<u-form-item style="font-size: 22px;" :leftIconStyle="{color: '#888', fontSize: '32rpx'}" label-width="300"
					:label-position="labelPosition" label="倒扣上提的吨位" prop="stuckPointDepth">
					<span v-if="model.stuckPointDepth"> {{model.stuckPointDepth}} t </span>
				</u-form-item>
			</view>
			<view class="u-config-item">
				<view class="u-item-title">计算公式</view>
				<view class="u-item-desc">G = H×G管 - H×S管×ρ液</view>
				<view class="u-item-desc">式中：</view>
				<view class="u-item-desc">G — 倒扣上提的吨位，t</view>
				<view class="u-item-desc">G管 — 井内管柱每米的重量，t</view>
				<view class="u-item-desc">H — 倒扣的深度，m</view>
				<view class="u-item-desc">S管 — 井内管柱截面积，㎡</view>
				<view class="u-item-desc">ρ液 — 井内液体的密度，t/m³</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				model: {
					depth: '',
					pipeWeight: '',
					pipeArea: '',
					liquidDensity: '',
					stuckPointDepth: ''
				},
				rules: {
					depth: [{
						required: true,
						message: '请输入倒扣的深度',
						trigger: 'blur'
					}],
					pipeWeight: [{
						required: true,
						message: '请输入井内管柱每米的重量',
						trigger: 'blur'
					}],
					pipeArea: [{
						required: true,
						message: '请输入井内管柱截面积',
						trigger: 'blur'
					}],
					liquidDensity: [{
						required: true,
						message: '请输入井内液体的密度',
						trigger: 'blur'
					}]
				},
				labelPosition: 'left',
				border: true,
				
			};
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		methods: {
			submit() {
				this.$refs.uForm.validate(valid => {
					if (valid) {
						const H = parseFloat(this.model.depth);
						const G管 = parseFloat(this.model.pipeWeight);
						const S管 = parseFloat(this.model.pipeArea);
						const ρ液 = parseFloat(this.model.liquidDensity);
						
						// 计算倒扣上提的吨位 G = H×G管 - H×S管×ρ液
						this.model.stuckPointDepth = (H * G管 - H * S管 * ρ液).toFixed(2);
					}
				});
			}
		}
	};
</script>

<style scoped lang="scss">
	.wrap {
		padding: 30rpx;
	}

	.u-config-wrap {
		margin-top: 30rpx;
	}

	.u-config-title {
		padding: 20rpx;
		font-size: 32rpx;
		font-weight: bold;
	}

	.u-config-item {
		padding: 20rpx;
	}

	.u-item-title {
		font-size: 28rpx;
		font-weight: bold;
		margin-bottom: 10rpx;
	}

	.u-item-desc {
		font-size: 24rpx;
		color: #666;
	}
</style> 